<?php require VIEWPATH. ADMIN_DIR. DIRECTORY_SEPARATOR. 'header.php'?>
<style type="text/css">
	/* 解决table中纯英文不换行 */
	#dynamic-table td {word-break: break-all;white-space: pre-wrap;max-width: 27%;}
	#dynamic-table td:nth-child(1) {width: 27%;}
</style>
<div class="page-header">
	<h1>
		校园公告列表
		<!-- 教师权限不可添加 -->
		<?php if($rmxUser['user_type'] != USER_TYPE_TEACHER): ?>
			<!-- <small>
				<a href="<?=admin_url('contents/announce_edit')?>" class="blue ml10">
					<i class="ace-icon fa fa-plus"></i> 发布校园公告
				</a>
			</small> -->
			<a href="<?=admin_url('contents/announce_edit')?>" class="btn btn-info a-custom">
				<i class="ace-icon fa fa-plus"></i> 发布校园公告
			</a>
		<?php endif ?>
	</h1>
</div>

<div class="col-xs-12">
	<table id="dynamic-table" class="table table-striped table-bordered table-hover" style="margin-top:10px">
		<thead>
			<tr>
				<th>公告标题</th>
				<th>公告类型</th>
				<th>发送时间</th>
				<th>修改时间</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody>
		</tbody>
	</table>
</div>

<?php require VIEWPATH. ADMIN_DIR. DIRECTORY_SEPARATOR. 'footer.php'?>
<script type="text/javascript">
	$(function(){

		// 班级表格
		$('#dynamic-table').dt({
			"ajaxUrl": '<?=admin_url('contents/get_announce_list')?>',
			"columns": [
	            // {"data": "announce_title"},
				{"data": function(ret){
					if(ret.is_top == 1) {
						return "<span class='text-danger'>[置顶]</span> " + ret.announce_title;
					} else {
						return ret.announce_title;
					}
				}},
				{"data": "announce_type"},
	            {"data": "createtime"},
	            {"data": "updatetime"},
	            {"data": function(ret){
					var action = '';
					// 如果是教师权限，只有任课班级的才能修改或删除
					if(ret.role_change) {
						action += '<a class="edit-grade green" href="<?=admin_url('contents/announce_edit')?>/'+ ret.id +'"><i class="fa fa-edit"></i> 编辑</a>';
	                	action += '&nbsp;&nbsp;&nbsp;&nbsp;<a class="text-danger delete-announce" href="javascript:" data-id=' + ret.id +  ' data-title=' + ret.announce_title + '><i class="fa fa-times"></i> 删除</a>';
					}
					return action;
	            }},
			]
		});
		// 删除公告
		$("body").on('click', '.delete-announce', function() {
			var id = $(this).data('id');
			var title = $(this).data('title');
			var posturl = "<?= admin_url("contents/delete_announce_action") ?>";
			var data = {
				'id': id
			};
			layer.confirm('确定删除：' + title + '？', { title:"提示", offset: '160px' }, function(){
				ajax_post(posturl, data, function() {
					// 刷新页面
					window.location.href = "<?= admin_url('contents/announce') ?>";
				});
			});
		});
	})
</script>